package com.yqg.protection.listenern;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.yqg.protection.controller.dto.ImportEquipmentUnitDto;
import com.yqg.protection.entity.EquipmentUnit;
import com.yqg.protection.mapper.EquipmentUnitMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * projectName:xf-service1
 * author:zxf
 * time:2024/10/17 16:37
 * description:
 */
@Component
public class EquipmentUnitListener extends AnalysisEventListener<ImportEquipmentUnitDto> {

    @Resource
    private EquipmentUnitMapper equipmentUnitMapper;

    @Override
    public void invoke(ImportEquipmentUnitDto importEquipmentUnitDto, AnalysisContext analysisContext) {
        EquipmentUnit equipmentUnit = new EquipmentUnit();
        BeanUtil.copyProperties(importEquipmentUnitDto, equipmentUnit, true);
        equipmentUnit.setIsDelete(0);
        equipmentUnitMapper.insert(equipmentUnit);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
